package org.haredot.mapper;

import org.apache.ibatis.annotations.*;
import org.haredot.entity.Btn;

import java.util.List;
import java.util.Map;

@Mapper
public interface BtnMapper {

    @Insert("insert into tb_btn(name, remark, status, func_id, create_time) values(#{name}, #{remark}, #{status}, #{func.id}, now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int saveBtn(Btn btn);

    @Select("select id, name, remark, status, func_id, create_time, update_time, disable_time from tb_btn where remark = #{remark} and flag = 0")
    @Result(property = "func.id", column = "func_id")
    Btn findBtnByRemark(String remark);

    @Select("select id, name, remark, status, func_id, create_time, update_time, disable_time from tb_btn where func_id = #{funcId} and flag = 0")
    @Result(property = "func.id", column = "func_id")
    List<Btn> findByFuncId(Long funcId);

    @Update("update tb_btn set status = #{status} where id = #{btnId} and flag = 0 and status = #{target}")
    int modifyStatusById(Map<String,? extends Number> stringHashMap);

    @Update("update tb_btn set flag = 1 where id = #{btnId} and flag = 0")
    int removeBtnById(Long btnId);
}
